import { FormSchema } from '@/components/Form';
import { BasicFormComponentKeys } from '@/components/Form/src/componentMap';
import Icon from '@/components/Icon/Icon.vue';
import { BasicColumn } from '@/components/Table';
import { router } from '@/router';
import { Button } from 'ant-design-vue';
import { h } from 'vue';

export const columns: BasicColumn[] = [
  {
    title: '模板id',
    dataIndex: 'id',
    width: 120,
  },
  {
    title: '模板名称',
    dataIndex: 'title',
    width: 120,
  },
  {
    title: '模板预览',
    dataIndex: 'file',
    width: 120,
    customRender({ text }) {
      return h(Button, {
        icon: h(Icon, { icon: 'ph:file-pdf-bold' }),
        type: 'link',
        onClick() {
          router.push({ name: 'PDFView', query: { file: decodeURIComponent(text) } });
        },
      });
    },
  },
  {
    title: '创建人',
    dataIndex: ['userInfo', 'name'],
    width: 120,
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    field: 'title',
    label: '模板名称',
    component: 'Input',
    colProps: { span: 8 },
  },
];

export const basicSchemas: FormSchema[] = [
  {
    field: 'file',
    label: '',
    component: BasicFormComponentKeys.Upload,
    componentProps: {
      className: 'p-7 border border-dashed border-current rounded-lg',
      api: (() => { }) as any,
      helpText: '单份文件小于30M',
      maxNumber: 1,
      maxSize: 1024 * 30,
    },
    required: true
  },
  {
    field: 'title',
    label: '模板名称',
    component: BasicFormComponentKeys.Input,
    componentProps: {
      maxlength: 90,
      showCount: true,
    },
    required: true
  },
];
